#include<iostream>
#include<mutex>
#include<thread>
#include<condition_variable>
using namespace std;

int main()
{
	mutex mut;
	condition_variable c;
	bool flag = false;

	thread t1([&]() {
		int i = 2;

		while (i <= 100) {
			unique_lock<mutex> lock(mut);
			while (!flag) {
				c.wait(lock);
			}
			//c.wait(lock);

			cout << i << endl;
			i += 2;
			flag = false;

			c.notify_one();
		}

	});

	thread t2([&]() {
		int j = 1;

		while (j <= 100) {
			unique_lock<mutex> lock(mut);
			while (flag) {
				c.wait(lock);
			}

			cout << j << endl;
			j += 2;
			flag = true;

			c.notify_one();
			//c.wait(lock);
		}
	});

	t1.join();
	t2.join();
	return 0;
}